-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support options with only a short flag #1256
Conversation
…n option constructor.
Side note: I hit a merge conflict when updating the branch which prompted me to look at how |
I created a I am thinking we might do a pre-release in June for v6, with short flags and variadic options. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thanks for doing this.
let longFlag; | ||
// Use original very loose parsing to maintain backwards compatibility for now, | ||
// which allowed for example unintended `-sw, --short-word` [sic]. | ||
const flagParts = flags.split(/[ |,]+/); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this pattern seems buggy if the comment is still accurate, did you intend to say /( |,)+/
there? or just /[ ,]+/
to match space or comma, or really wanted to add a pipe |
to the mix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pipe is really in the mix. From the README:
Each option can have a short flag (single character) and a long name, separated by a comma or space or vertical bar ('|').
The comment is about -sw
which is neither a short flag nor a long name.
Pull Request
Problem
Users may wish to declare an option which has only a short flag and no long flag.
Defining just a short flag for an option appeared to almost work, but was not actually supported internally.
See: #1249
Solution
Extend option flag parsing to allow short, or long, or both. Extend the support to the custom option flags for
.helpOption()
and.version()
too.ChangeLog